package com.auguigu.springlcoud.service.impl;

import cn.hutool.core.lang.UUID;
import com.auguigu.springlcoud.service.IMessageProvider;
import lombok.extern.slf4j.Slf4j;
import org.springframework.cloud.stream.annotation.EnableBinding;
import org.springframework.cloud.stream.messaging.Source;
import org.springframework.messaging.MessageChannel;
import org.springframework.messaging.support.MessageBuilder;

import javax.annotation.Resource;

/**
 * @author fys2000
 * @date 2020/7/22 10:21
 * @since 最早从哪个版本开始的，如v1.0.1
 */
@EnableBinding(Source.class)        //定义消息的推送管道，这里是输出源
@Slf4j
public class MessageProviderImpl implements IMessageProvider {

    //消息发送管道
    @Resource
    private MessageChannel output;

    @Override
    public String send() {
        final String serial = UUID.fastUUID().toString();
        output.send(MessageBuilder.withPayload(serial).build());
        log.info("发送消息 -> ：{}", serial);
        return null;
    }
}
